// 处理add相关URL
const productModel = require('../models/add')

let fn_add = async (ctx, next) => {
    let data = {}
    let note = new productModel({
        name: '晨光3X3四分条优事贴100页YS-13',
        detail: '便利贴',
        picture: [
            { imageUrl: 'http://www.mg.cn/public/images/17/49/f6/9017fede2770fafbc342b8f72a0fe8bcac4d3424.jpg?1566529298#h' },
            { imageUrl: 'http://www.mg.cn/public/images/61/bf/f9/05477066c287fb4ecb5e2ba079c5fb6f1765c601.jpg?1566529299#h' },
            { imageUrl: 'http://www.mg.cn/public/images/2e/46/e4/2d8de644b7e373a6e4209a6ec67b95513f48aeef.jpg?1566529299#h' },
            { imageUrl: 'http://www.mg.cn/public/images/2e/46/e4/2d8de644b7e373a6e4209a6ec67b95513f48aeef.jpg?1566529299#h' },
            { imageUrl: 'http://www.mg.cn/public/images/52/ff/60/bab4e24afa076d2a93b4aac2e6afa79c7f43f92d.jpg?1566529299#h' },
        ],
        price: 2.35,
        stock: 99,
        code: 'YS-13',
        brank: 'M&G',
        type: 'stationery',
        category: 'note'
    })

    await note.save((err, stickyNote) => {
        if (err) return console.error(err);
        console.log('stationery is saved', stickyNote);
    })

    await productModel.find(function (err, items) {
        if (err) return console.error(err);
        data = {
            save: 'ok',
            list: items
        }
    })
    
    ctx.response.body = await {
        code: 0,
        data,
        msg: 'ok',
        next: true
    }
}

module.exports = {
    'GET /add': fn_add
}